package com.hj.ipproxy.util;

import java.util.HashMap;
import java.util.Map;

import com.hj.tools.StringUtil;

/**
 * 代理IP工具类
 * @author HJ
 */
public class ProxyIpUtil {
	private ProxyIpUtil(){}
	private static Map<String, String> userAgent = new HashMap<String, String>();
	
	static{
		userAgent.put("FireFox", "Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0");
		userAgent.put("IE", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)");
		userAgent.put("Chrome", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36");
	}
	
	/**
	 * 获取火狐的User-Agent
	 */
	public static String getFireFoxUA(){
		return userAgent.get("FireFox");
	}
	
	/**
	 * 获取IE的User-Agent
	 */
	public static String getIEUA(){
		return userAgent.get("IE");
	}
	
	/**
	 * 获取谷哥的User-Agent
	 */
	public static String getChromeUA(){
		return userAgent.get("Chrome");
	}
	
	//\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])
	//\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])
	//\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])
	//\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b
	public static final String REGX_IP = "(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)){3}";
	public static final String NEW_LINE = System.getProperty("line.separator");
	
	public static int formatPort(String portStr){
		int port = Integer.parseInt(StringUtil.match(portStr, "\\d{2,4}")[0]);
		return port;
	}
}
